<admintpl file="header" />
</head>
<body class="J_scroll_fixed">
    <div class="wrap js-check-wrap">
        <ul class="nav nav-tabs">
            <li class="active"><a href="{:U('Tui/Agent/Discount')}" target="_self">游戏折扣管理</a></li>
        </ul>
        <form class="well form-search" method="get" action="{:U('Tui/Agent/Discount')}">
            <div class="search_type cc mb10">
                <div class="mb10">
                    <span class="mr20">
                        渠道名： 
                        <select class="select_2" name="agent" id="selected_id">
                            <empty name="formget['agent']">
                                <option value="" selected="selected">全部</option>
                            </empty>
                            <notempty name="formget['agent']">
                                <option value="">全部</option>
                            </notempty>
                            <volist name="agents" id="vo">
                                <if condition="$vo.id eq $formget['agent']">
                                    <option value="{$vo.id}" selected="selected">{$vo.user_login}</option>
                                <else />
                                    <option value="{$vo.id}">{$vo.user_login}</option>
                                </if>
                            </volist>
                        </select>
                        &nbsp;&nbsp;
                        游戏名：
                        <select class="select_2" name="appid" id="selected_id">
                            <option value="-1">全部</option>
                            <volist name="games" id="vo">
                                <if condition="$vo.app_id eq $formget['appid']">
                                    <option value="{$vo.app_id}" selected="selected">{$vo.gamename}</option>
                                <else />
                                    <option value="{$vo.app_id}">{$vo.gamename}</option>
                                </if>
                            </volist>
                        </select>
                        &nbsp;&nbsp; 
                        <input type="submit" class="btn btn-primary" value="搜索" />
                    </span>
                </div>
            </div>
        </form>

        <form class="js-ajax-form" action="" method="post">
            <table class="table table-hover table-bordered table-list">
                <thead>
                    <tr>
                        <th width="20">ID</th>
                        <th width="50">渠道名</th> 
                        <th width="50">渠道联系人</th>
                        <th width="50">游戏名</th>
                        <th width="50">平台币充值折扣</th>
                        <th width="50">操作</th>
                    </tr>
                </thead>

                <foreach name="items" item="vo">
                    <tr>
                        <td>{$vo.id}</td>
                        <td>{$vo.user_login}</td>
                        <td>{$vo.user_nicename}</td>
                        <td>{$vo.gamename}</td>
                        <td>{$vo.agent_rate}</td>
                        <td>
                            <a href="#" class="edit_rate_btn" data-rate="{$vo.agent_rate}" data-id="{$vo.id}">编辑折扣</a> 
                        </td>                          
                    </tr>
                </foreach>				
            </table>
            <div class="pagination">{$Page}</div>
        </form>
    </div>
    <script src="__PUBLIC__/js/common.js"></script>
    <script>
        $(".edit_rate_btn").click(function(){
            var id=$(this).attr("data-id");
            var rate=$(this).attr("data-rate");
            var new_rate=prompt("请输入新的折扣",rate);
            if (new_rate!==null && new_rate!=="" && !isNaN(new_rate)){
                $.post("{:U('tui/agent/change_agent_rate')}",{"id":id,"new_rate":new_rate},function(data){
                    if(data.error==='0'){
                        location.reload();
                    }else{
                        alert(data.msg);
                    }
                });
            }
        });
        
        $(".edit_rebate_btn").click(function(){
            var id=$(this).attr("data-id");
            var rate=$(this).attr("data-rate");
            var new_rate=prompt("请输入新的返点",rate);
            if (new_rate!==null && new_rate!=="" && !isNaN(new_rate)){
                $.post("{:U('tui/agent/change_agent_rebate')}",{"id":id,"new_rate":new_rate},function(data){
                    if(data.error==='0'){
                        location.reload();
                    }else{
                        alert(data.msg);
                    }
                });
            }
        });
    </script>
</body>
</html>